<template>
  <view class="card-style">
    <!-- 标题区域 -->
    <text class="title" @click="titleClick">{{ title }}</text>
    
    <!-- 信息栏（作者、评论、时间等） -->
    <view class="tips-bar">
      <text class="top-tag" v-if="isTop">置顶</text>
      <text class="author" @click="authorClick">{{ author }}</text>
      <text class="comments">{{ comments }} 评</text>
      <view class="time-wrap">
        <text class="time">{{ time }}</text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: "NewsView",
  // 自定义属性（props）定义
  props: {
    title: {
      type: String,
      default: "默认标题",
      required: true
    },
    isTop: {
      type: Boolean,
      default: false
    },
    author: {
      type: String,
      default: "默认作者",
      required: true
    },
    comments: {
      type: Number,
      default: 0,
      required: true
    },
    time: {
      type: String,
      default: "2025.01.01",
      required: true
    }
  },
  // 自定义事件方法
  methods: {
    titleClick() {
      this.$emit("titleClick", this.title);
    },
    authorClick() {
      this.$emit("authorClick", this.author);
    }
  },
  // 生命周期钩子
  created() {
    console.log("组件创建完成");
  },
  mounted() {
    console.log("组件挂载到页面");
  }
};
</script>

<style scoped>
.card-style {
  background-color: #dbffe4;
  padding: 10rpx;
  margin-bottom: 10rpx;
}

.title {
  font-size: 32rpx;
  font-weight: bold;
  display: block;
  margin-bottom: 10rpx;
}

.tips-bar {
  display: flex;
  font-size: 24rpx;
  color: #999;
}

.tips-bar text {
  margin-right: 20rpx;
}

.top-tag {
  color: #f00;
}

.time-wrap {
  flex: 1;
  display: flex;
  justify-content: flex-end;
}
</style>